"""
@FileName：Fourth _Question.py\n
@Author：顾聪聪\n
@Time：2021/9/14 11:33\n
@Department：宿州学院\n
"""
'''
绘制正态分布N(10,2)和N(12,3)的概率密度函数图
'''
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']  # 显示汉字
plt.rcParams['axes.unicode_minus'] = False  # 显示负号
plt.rcParams['savefig.dpi'] = 100  # 图片质量

mu1 = 10
sigma1 = 2
mu2 = 12
sigma2 = 3


# 定义函数求概率密度，这个函数其实就是正态分布的公式
def norm_fun(x, mu, sigma):
    return np.exp(-((x - mu) ** 2) / (2 * sigma ** 2)) / (sigma * np.sqrt(2 * np.pi))


# 画图
x = np.linspace(1, 25, 100)
y1 = norm_fun(x, mu1, sigma1)
y2 = norm_fun(x, mu2, sigma2)

fig, ax = plt.subplots()
ax.plot(x, y1, "r-", linewidth=2, label='f(x1)')
ax.plot(x, y2, "b-", linewidth=2, label='f(x2)')
ax.set(ylabel='f(x)', xlabel='x')
ax.legend()
ax.grid(True)

plt.show()
